package com.zjdiepu.www.manage.api.third;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.core.ApiResponse;
import com.zjdiepu.www.ibiz.third.IJuheAreaService;
import com.zjdiepu.www.ibiz.third.IJuheCityService;
import com.zjdiepu.www.ibiz.third.IJuheProvinceService;
import com.zjdiepu.www.model.third.dto.JuheArea;
import com.zjdiepu.www.model.third.dto.JuheCity;
import com.zjdiepu.www.model.third.dto.JuheProvince;
import com.zjdiepu.www.model.third.ext.JuheAreaExt;
import com.zjdiepu.www.model.third.ext.JuheCityExt;
import com.zjdiepu.www.model.third.ext.JuheProvinceExt;
@RestController
@RequestMapping(value = "AreaController", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
@Api(tags = { "地区" }, produces = "application/json;charset=UTF-8")
public class AreaController extends BaseController{

	@Resource
	private IJuheProvinceService juheProvinceService;
	
	@Resource
	private IJuheCityService juheCityService;
	
	@Resource
	private IJuheAreaService juheAreaService;
	
	
	@ApiOperation(value = "获取所有省数据",response = ApiResponse.class, httpMethod="POST", tags={"列表"})
	@RequestMapping(value = "getAllProvince", method = RequestMethod.POST)
	public ApiResponse getAllProvince(){
		JuheProvinceExt juheProvinceExt=new JuheProvinceExt();
		juheProvinceExt.setBaseWhere();
		juheProvinceExt.withOutPage();
		List<JuheProvince> list=juheProvinceService.selectByExt(juheProvinceExt);
		if(list!=null && list.size()>0){
			return ApiResponse.success(list);
		}
		return ApiResponse.success(false);
	}
	
	@ApiOperation(value = "根据省id获取地区数据",response = ApiResponse.class, httpMethod="POST", tags={"列表"})
	@RequestMapping(value = "getCityByProvinceId", method = RequestMethod.POST)
	public ApiResponse getCityByProvinceId(String proId){
		JuheCityExt juheCityExt=new JuheCityExt();
		juheCityExt.setBaseWhere();
		juheCityExt.withOutPage();
		juheCityExt.setProId(proId);
		List<JuheCity> list=juheCityService.selectByExt(juheCityExt);
		if(list!=null && list.size()>0){
			return ApiResponse.success(list);
		}
		return ApiResponse.success(false);
	}
	
	@ApiOperation(value = "根据省id获取地区数据",response = ApiResponse.class, httpMethod="POST", tags={"列表"})
	@RequestMapping(value = "getAreaByCityId", method = RequestMethod.POST)
	public ApiResponse getAreaByCityId(String cityId){
		JuheAreaExt juheAreaExt=new JuheAreaExt();
		juheAreaExt.setBaseWhere();
		juheAreaExt.withOutPage();
		juheAreaExt.setCityId(cityId);
		List<JuheArea> list=juheAreaService.selectByExt(juheAreaExt);
		if(list!=null && list.size()>0){
			JuheArea juheArea=new JuheArea();
//			juheArea.setAreaCode("000000");
			juheArea.setAreaId("000000");
			juheArea.setAreaName("未知地区");
			list.add(juheArea);
			return ApiResponse.success(list);
		}
		return ApiResponse.success(false);
	}
}
